package models;

import java.text.DecimalFormat;
import java.util.TreeSet;


public class ResultPair implements Comparable<ResultPair>
{

    private String url;
    private String htmlLink;
    private double confidence;


    public ResultPair(String url, double confidence, String htmlLink)
    {
        this.url = url;
        this.confidence = confidence;
        this.htmlLink = htmlLink;
    }


    public String getUrl()
    {
        return url;
    }


    public double getConfidence()
    {
        return confidence;
    }


    public String getHtmlLink()
    {
        return htmlLink;
    }


    @Override
    public int compareTo(ResultPair rp)
    {
        if(this.confidence < rp.confidence) {
            return -1;
        } else {
            return 1;
        }
    }


    @Override
    public String toString()
    {
        return this.url + " " + this.confidence;
    }


    public static String setToHtmlTable(TreeSet<ResultPair> rpList)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("<table style=\"table-layout: fixed; width: 100%\" class=\"table table-condensed\">");
        sb.append("<colgroup><col width=\"*\"</col><col width=\"25%\"</col></colgroup>");
        sb.append("<thead><tr><th>Instance</th><th>Confidence</th></tr></thead><tbody>");

        for(ResultPair rp : rpList.descendingSet()) {
            sb.append("<tr><td>" + rp.getHtmlLink() + "</td><td>" + new DecimalFormat("#.####").format(rp.getConfidence()) + "</td></tr>");
        }
        sb.append("</tbody></table>");
        return sb.toString();
    }

}
